from lxml import etree
from lxml.builder import E
import logging
_logging = logging.getLogger(__name__)
xml = etree.parse('./ir_ui_menu.xml')
root = xml.getroot()


def generate_menus_py(root):
    menus_str = "<?xml version='1.0' encoding='UTF-8'?>\n<odoo>\n"
    for record in root:
        record_dict = {}
        for field in record:
            name = field.get('name')
            eval = field.get('eval')
            ref = field.get('ref')
            value = field.text
            if(eval != None):
                record_dict[name] = eval
            if(ref != None):
                record_dict[name] = ref
            if(value != None):
                record_dict[name] = value
        menus_str += ' <menuitem name="%s" parent="%s" id="%s" action="%s" sequence="%s" groups="%s"/>\n' % (
            record_dict['name'], record_dict['parent_id'], record.get('id'), record_dict['action'], record_dict['sequence'], record_dict['groups_id'])
    menus_str += '</odoo>'
    # print(menus_str)
    return menus_str


generate_menus_py(root)
